/*
EP3D is a real-time 3D planet engine , which in addition to providing 
substandard scene rendering and scene management, of course, it also 
provides some basic class libraries to build the entire virtual 
planet, or even the entire universe.

Copyright (C) 2010  Hongjiang Zhang	(zhjwyat@gmail.com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EP3D_FRUSTUM_H
#define EP3D_FRUSTUM_H
#include "EP3DPlane3.h"
#include "EP3DMatrix4.h"
#include "EP3DBoundingBox.h"

namespace EP3D
{
	class EP3DEXPORT Frustum
	{
	public:
		enum FrustumPlane
		{
			FP_FAR = 0,
			FP_NEAR,
			FP_LEFT,
			FP_RIGHT,
			FP_BOTTOM,
			FP_TOP,

			FP_COUNT
		};

		Frustum(void);
		Frustum(const Matrix4f& m);

		Vector3f GetFarLeftTop() const;
		Vector3f GetFarLeftBottom() const;
		Vector3f GetFarRightTop() const;
		Vector3f GetFarRightBottom() const;

		void CalculateBoundingBox();
		const BBox3f& GetBoundingBox() const;

		void Transform(const Matrix4f& m);
		void SetFrom(const Matrix4f& m);

		Matrix4f& GetViewMatrix();
		Matrix4f& GetProjectionMatrix();

		const Matrix4f& GetViewMatrix() const;
		const Matrix4f& GetProjectionMatrix() const;

		bool Contains(const Vector3f& v) const;
		bool Contains(const BBox3f& box) const;
		bool Intersects(const BBox3f& box) const;

		Vector3f m_kPosition;
		Plane3f m_kPlanes[FP_COUNT];
		BBox3f m_kBBox;

	private:
		Matrix4f m_kViewMat;
		Matrix4f m_kProjMat;
	};
}

#endif
